;-------------------------------------------------------------------------------
; Mad Mix Music ; Write data with no use of Track 0 (reserved for file index)
;-------------------------------------------------------------------------------
; 23/06/2009 -> July 2009 by Megachur
;-------------------------------------------------------------------------------
WINAPE_SAVE equ 0

	IF WINAPE_SAVE

	write direct "a:MENU.BIN",start

	ELSE

;	run start

	ENDIF
; ---------------------------
begin_menu		equ &1000
DIRECTORY_LAST_SECTOR_USER_DEFINE	equ &c8	; non standard AMSDOS value
; ---------------------------
LIST
	org begin_menu
NOLIST
.start
	di

	ld hl,&0038
	ld (hl),&c3
	inc hl
	ld (hl),interrupt
	inc hl
	ld (hl),interrupt/&100

	ei

	xor a
	call Set_Drive_Head_Number

load_file_from_disk_b

	ld a,1
	call Set_Drive_Number		; to tell which drive to use

	ld hl,Memory_file
	ld d,h
	ld e,l
	inc de
	ld bc,&3fff
	ld (hl),&00
	ldir

filename_next
;	ld hl,filename_first
;	ld hl,filename_second
	ld hl,filename_third

	ld a,(hl)
	or a
	ret z	; end of list filename

	push hl

	ld de,Memory_file
	ld b,d
	ld c,e

	call LOADFILE

	pop hl

	or a
	jr nz,filename_next	; retry

	push hl

	ld a,(File_NbBlock)
	ld h,&00
	ld l,a
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl	; nb block *128 = file_length
	ld (Memory_file_Length),hl

	pop hl
	push hl

	call write_file_to_disk_a

	pop hl

	or a
	jp nz,Set_Motor_Off

	ld bc,11
	add hl,bc
	ld (filename_next+1),hl
	jr load_file_from_disk_b

write_file_to_disk_a
	xor a
	call Set_Drive_Number		; to tell which drive to use

	ld (Filename_Ptr),hl
	ld de,Memory_file
	ld bc,Memory_Directory_Tempo

	call WRITEFILE

	or a
	ret nz

	ld hl,(Memory_Directory_Data)
	ld (Memory_Write_Data),hl

	ld a,DIRECTORY_FIRST_TRACK
	ld (NCN),a
	ld (Write_Sector_Parameter_C),a

	ld a,FDC_Command_Seek
	call FDC_Command
	ret nz

	ld a,(Get_Place_Data_Of_Directory_Sector_Index)
	ld (Write_Sector_Parameter_R),a
	ld (Write_Sector_Parameter_EOT),a

	ld a,FDC_Command_Write_Data
	call FDC_Command
	ret nz

	jp Set_Motor_Off
;-------------------------------------------------------------------------------
.interrupt
;-------------------------------------------------------------------------------
	di
	push af
	push bc
	push de
	push hl
	push ix
	push iy

;	ld bc,&7f10
;	out (c),c
;couleur_int equ $+1
;	ld a,&4b
;	xor 1
;	ld (couleur_int),a
;	out (c),a

	ld hl,interrupt_next_counter+1

	ld b,&f5
	in a,(c)
	rra
	jr nc,interrupt_next
	ld (hl),&0
	jr interrupt_next_counter
interrupt_next
	defs 2,0
	inc (hl)
interrupt_next_counter
	ld a,&ff
	cp 6
	jr c,interrupt_next_bad_crtc
	xor a
interrupt_next_bad_crtc
	ld (hl),a

	ld hl,interrupt_list
	ld b,&00
	add a,a
	ld c,a
	add hl,bc
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	jp (hl)
interrupt_list
	dw interrupt_back
	dw interrupt_Sense_Interrupt
	dw interrupt_back
	dw interrupt_back
	dw interrupt_back
	dw interrupt_back

.interrupt_Sense_Interrupt

	call Sense_Interrupt

interrupt_back
	pop iy
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ei
	reti

;-------------------------------------------------------------------------------
	read	"..\Common_Sources\FDC_v2_e.asm"
;-------------------------------------------------------------------------------
filename_first
	db "5THGEAR MUS"
	db "7GATES1 MUS"		;23
	db "7GATES2 MUS"		;55
	db "AIRBALL MUS"		;62
	db "AKSCR   PAK"		;82
	db "ANCOOL1 MUS"		;0
	db "ANCOOL2 MUS"		;1
	db "ANCOOL3 MUS"		;2
	db "ANCOOL4 MUS"		;3
	db "ANCOOL5 MUS"		;44
	db "ANCOOL6 MUS"		;45
	db "ANCOOL7 MUS"		;125
	db "ARCHON  MUS"		;58
	db "ARPYREMIMUS"		;124
	db "ASTAR1  MUS"		;4
	db "ASTAR2  MUS"		;5
	db "ATOMINO1MME"		;117
	db "ATOMINO2MME"		;118
	db "ATOMINO3MME"		;119
	db "ATOMIX  MUS"		;46
	db "AXLFOLEYMUS"		;51
	db "BACHTHEFMUS"		;57
	db "BEATNIC PAK"		;83
	db "CHAMBER3MUS"		;7
	db "CHAMBER4MUS"		;8
	db "CHAMBER5MUS"		;9
	db "CHAMBER6MUS"		;10
	db "CHAMBER8MUS"		;11
	db "CHAM1   PAK"		;101
	db "CHAM3   PAK"		;102
	db "CUD1    MUS"		;12
	db "CUD2    MUS"		;13
	db "CUD4    MUS"		;14
	db "CUD10   MUS"		;15
	db "CUD12   MUS"		;16
	db "DRAGON0 MUS"		;47
	db "DRAGON1 MUS"		;48
	db "DRAGON2 MUS"		;49
	db "DRAGON3 MUS"		;50
	db "ENS1    MUS"		;126
	db "ENS2    MUS"		;127
	db "ENS3    MUS"		;128
	db "ENS4    MUS"		;129
	db "ENS5    MUS"		;130
	db "ENS6    MUS"		;131
	db "LANDS1  MUS"		;64
	db "LANDS3  MUS"		;65
	db "LANDS4  MUS"		;66
	db "LANDS5  MUS"		;67
	db "LANDS6  MUS"		;68
	db "LANDS7  MUS"		;69
	db "LANDS8  MUS"		;70
	db "LANDS9  MUS"		;71
	db "GAMBOL  MUS"		;56
	db "GRDMONSTMUS"		;24
	db "GC2     MUS"		;132
	db "INSECT  MUS"		;105
	db "NY3     MUS"		;21
	db "LAP1    MUS"		;107
	db "LAP2    MUS"		;108
	db "LAP3    MUS"		;109
	db "LAP4    MUS"		;110
	db "LAP5    MUS"		;111
	db "LAP6    MUS"		;112
	db "LAP7    MUS"		;113
	db "LAP8    MUS"		;114
	db "LAP9    MUS"		;115
	db "LAP10   MUS"		;116
	db "TERA3   MUS"		;29
	db "TERA5   MUS"		;30
	db "TERA61  MUS"		;31
	db "TERA62  MUS"		;32
	db "TERA71  MUS"		;33
	db "TERA72  MUS"		;34
	db "TERA73  MUS"		;35
	db "TERA74  MUS"		;36
	db "TERA75  MUS"		;37
	db "TERA76  MUS"		;38
	db "MARTGALRMUS"		;63
	db "MASTER1 MME"		;103
	db "MASTER2 MME"		;104
	db "LOST2   MUS"		;42
	db "LOST4   MUS"		;43
	db "NY2     MUS"		;20
	db "TLB7    MME"		;123
	db "REPLI1  MUS"		;22
	db "PREHIS5 MUS"		;72
	db "PREHIS6 MUS"		;73
	db "PREHIS7 MUS"		;74
	db "PREHIS14MUS"		;75
	db "PREHIS3 MME"		;77
	db "PREHIS8 MME"		;78
	db "PREHIS9 MME"		;79
	db "PREHIS12MME"		;80
	db "PREHIS10PAK"		;84
	db "MEDUSA  MUS"		;52
	db "RING    MUS"		;53
	db "ROM2    MME"		;121
	db "ROM3    MME"		;122
	db "WEIRD   MUS"		;41
	db "MAD13   MUS"		;18
	db "MADMUS2 MUS"		;19
	db "SOWATT1 MUS"		;25
	db "SOWATT11MUS"		;26
	db "SPACEBALMUS"		;27
	db "STORM1  MUS"		;28
	db "STORM2  MUS"		;106
	db "SYNTER2 MUS"		;59
	db "SYNTER5 MUS"		;60
	db "SYNTER23MUS"		;61
	db "TANGRAM1MME"		; ?
	db "TANGRAM2MME"		; ?
; end of first disk
	db 0
filename_second
	db "THALION MUS"		;6
	db "TURICAN1MUS"		;54
	db "TUR1    PAK"		;76
	db "TUR2    PAK"		;85
	db "TUR3    PAK"		;86
	db "TUR4    PAK"		;87
	db "COSO9   PAK"		;95
	db "COSO19  PAK"		;96
	db "COSO28  PAK"		;97
	db "COSO37  PAK"		;98
	db "COSO49  PAK"		;99
	db "COSO58  PAK"		;100
	db "ULM1    MME"		;81
	db "MAD2    MME"		;120
	db "MAD30   MUS"		;133
	db "WARP1   MUS"		;39
	db "WARP2   MUS"		;40
	db "WINGS0  PAK"		;88
	db "WINGS1  PAK"		;89
	db "WINGS2  PAK"		;90
	db "WINGS3  PAK"		;91
	db "WINGS5  PAK"		;92
	db "WINGS6  PAK"		;93
	db "WINGS7  PAK"		;94
	db "MAD3    MUS"		;?
	db "DESHORTYMUS"		;.
	db "JAZZY   MUS"		;.
	db "POKER   MUS"		;.
	db "SUPSONICMUS"		;.
	db "STNEWS61MUS"		;.
	db "DEMO6   MUS"		;.
	db "DEMO8   MUS"		;.
	db "DEMO9   MUS"		;.
	db "LM      MUS"		;.
	db "LOADER1 MUS"		;.
	db "LOADER  MUS"		;.
	db "MAINMENUMUS"		;.
	db "FLETCH  MME"		;.
	db "QUIZMASTMUS"		;.doublon ?
	db "CONFED2 MUS"		; ?
	db "TLB00   PAK"		;.
	db "MMAX03  MUS"		;.
	db "MMAX04  MUS"		;.
	db "MMAX07  MUS"		;.
	db "MAX066  MUS"		; ?
	db 0
filename_third
	db "MADMIXPL   "		; MadMix player executabl !
	db 0
; ---------------------------
Memory_Directory_Tempo
	defs &200,0
; ---------------------------
Memory_file
;Memory_file_Length equ $-Memory_file
;-------------------------------------------------------------------------------
; FDC Read
